<template>
	<view class="">
		<u-loading-page :loading="isLoading"></u-loading-page>
		<view class="app" v-show="!isLoading">
			<u-form ref="uForm" :model="obj.configuration"  size="medium" labelWidth="160rpx" class="u-p-l-30 u-p-r-20">
				<u-form-item label="未付款订单">
					<u-radio-group v-model="obj.configuration.order_is_close">
						<u-radio customStyle="margin-right:32rpx" :name="0" label="永不关闭"></u-radio>
						<u-radio :name="1" label="自定义关闭时间"></u-radio>
					</u-radio-group>
				</u-form-item>

				<u-form-item v-if="obj.configuration.order_is_close == 1" label="关闭时间"><u-input v-model.number="obj.configuration.order_close_time"></u-input></u-form-item>
				<u-alert type="primary" description="订单取消时间必须在20-1440分钟之间"></u-alert>
				<u-form-item label="自动收货">
					<u-radio-group v-model="obj.configuration.is_auto_receiving">
						<u-radio customStyle="margin-right:32rpx" :name="0" label="不自动收货"></u-radio>
						<u-radio :name="1" label="自定义收货时间"></u-radio>
					</u-radio-group>
				</u-form-item>

				<u-form-item v-if="obj.configuration.is_auto_receiving == 1" label="收货时间" prop="receiving_time">
					<u-input v-model="obj.configuration.receiving_time" style="width:180px;margin-right:10px;margin-left:10px">
						<u-text slot="prefix" text="发货"></u-text>
						<u-text slot="suffix" text="天后自动收货"></u-text>
					</u-input>
				</u-form-item>
				<u-alert type="primary" description="自动确认收货时间必须在7-30天之间"></u-alert>
				<u-form-item label="订单完结" prop="order_end_time">
					<u-input v-model="obj.configuration.order_end_time" style="width:180px;margin-right:10px;margin-left:10px">
						<u-text slot="prefix" text="订单收货"></u-text>
						<u-text slot="suffix" text="天后自动完结订单"></u-text>
					</u-input>

					<!-- <div style="color:#909399;font-size:12px;">自动确认收货时间必须在7-30天之间</div> -->
				</u-form-item>
				<u-form-item label="分销佣金" prop="agent_get_money_time">
					<u-input v-model="obj.configuration.agent_get_money_time" style="width:180px;margin-right:10px;margin-left:10px">
						<u-text slot="prefix" text="订单完结"></u-text>
						<u-text slot="suffix" text="天后,获得分销佣金"></u-text>
					</u-input>

					<!-- <div style="color:#909399;font-size:12px;">订单取消时间必须在20-1440分钟之间</div> -->
				</u-form-item>
				<u-form-item label="发票设置"><u-switch v-model="obj.configuration.is_invoice" :activeValue="1" :inactiveValue="0" size="20"></u-switch></u-form-item>
				<u-form-item label="订单评价"><u-switch v-model="obj.configuration.order_evaluate" :activeValue="1" :inactiveValue="0" size="20"></u-switch></u-form-item>
				<u-form-item label="显示评价"><u-switch v-model="obj.configuration.is_show_evaluate" :activeValue="1" :inactiveValue="0" size="20"></u-switch></u-form-item>
				<u-form-item label="评价审核"><u-switch v-model="obj.configuration.audit_evaluate" :activeValue="1" :inactiveValue="0" size="20"></u-switch></u-form-item>
			</u-form>
				<view class="u-flex u-flex-items-center footer">
					<u-button size="small" shape="circle" @click="cancal">取消</u-button>
					<u-button class="u-m-l-60" type="primary" size="small" shape="circle" @click="saveData">确定</u-button>
				</view>
				<u-toast ref="uToast"></u-toast>
			</view>
		</view>
	</template>
</template>

<script>
export default {
	data() {
		return {
			isLoading: false,
			checkList: [],
			obj: {
				type: 'tradeSetting',
				status: 1,
				configuration: {
					agent_get_money_time: 0,
					order_is_close: 0,
					order_close_time: 0,
					is_auto_receiving: 0,
					receiving_time: 0,
					order_end_time: 0,
					deal_enhance: 0,
					invoice: [],
					order_evaluate: 1,
					is_show_evaluate: 1,
					audit_evaluate: 1,
					is_invoice: 0
				}
			},
			itemRules: {
				receiving_time: [
					{
						type: 'string',
						required: true,
						message: '请输入',
						trigger: ['blur', 'change']
					}
				],
				order_end_time: [
					{
						type: 'string',
						required: true,
						message: '请输入',
						trigger: ['blur', 'change']
					}
				],
				order_close_time: [
					{
						type: 'string',
						required: true,
						message: '请输入',
						trigger: ['blur', 'change']
					}
				],
			}
		};
	},
	components: {},
	onLoad() {
		this.getConfig();
	},
	onReady() {
		this.$refs.uForm.setRules(this.itemRules);
	},
	onPullDownRefresh() {
		this.getConfig()
	},
	methods: {
		//获取站点配置数据
		getConfig(type) {
			this.isLoading = true;
	uni.$u.http
		.get('/madmin/configuration/tradeSetting',{custom:{id:12}})
				.then(res => {
					uni.stopPullDownRefresh()
					this.isLoading = false;
					if (res.msg) {
						this.obj = res.msg;
					}
				})
				.catch(e => {
					this.isLoading = false;
				});
		},
		//保存数据
		saveData() {
			
			this.$refs.uForm
				.validate().then(res=>{
					// this.isLoading = true;
					if (this.obj.update_time) {
						//更新
					uni.$u.http
						.put('/madmin/configuration/tradeSetting', this.obj,{custom:{id:12}})
							.then(res => {
								this.$refs.uToast.show({
									message: '更新成功',
									type: 'success',
									complete: () => {
										this.getConfig();
									}
								});
							})
							.catch(e => {
								// this.isLoading = false;
							});
					} else {
					//新增
					uni.$u.http
						.post('/madmin/configuration/tradeSetting', this.obj,{custom:{id:12}})
							.then(res => {
								this.$refs.uToast.show({
									message: '新增成功',
									type: 'success',
									complete: () => {
										this.getConfig();
									}
								});
							})
							.catch(e => {
								this.isLoading = false;
							});
					}
				}).catch(err=>{
					
				})
	
		},
		cancal() {
			uni.$u.route({
				type: 'navigateBack',
				delta: 1
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.app {
	background: #fff;
}
.footer {
	position: fixed;
	bottom: 0;
	left: 0;
	width: 100%;
	box-sizing: border-box;
}
</style>
